<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/18
 * Time: 10:21
 */

namespace app\api\controller;


use think\Controller;
use app\admin\model\order\OrderQueue;
class Timing extends Controller
{

    public function sms(){
        $order = new \app\admin\model\order\Order();
        //2 小时内
        $where = [
            'pay_status'=>'1',
        ];
        $list = $order->alias('o')
            ->join('fa_order_queue q ','q.order_id = o.order_id')
            ->where($where)
            ->whereTime('appoint_time',['between'=>[strtotime('-2 hours'),date('Y-m-d H:i:s')]])
            ->field('o.order_id,q.id')
            ->select();
        if($list){
            $listArr = collection($list)->toArray();

            $orderQueue = new OrderQueue();
            $insertData = [];
            foreach ($listArr as $k=>$v){
                if(!$v['id']) {
                    $order->sendSms($v['order_id']);
                    //是否已发送
                    $insertData[] =
                        [
                            'order_id'=>$v['order_id']
                        ];
                }
            }
            if(!empty($insertData)){
                $orderQueue->insertAll($insertData);
            }
        }

    }

}